package com.yvtian.utils;

import com.yvtian.admin.pojo.SysLog;
import com.yvtian.admin.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.File;

@Slf4j
//必须要注册到spring的容器
//不能new这个类，只能在spring的容器里面获取
@Component
public class AsyncUtil {

    @Autowired
    private SysLogService SysLogService;

    /**
     * 删除服务器的头像图片。
     *
     * 不能和调用者在同一个类下。
     *
     * @param path
     */
    @Async
    public  void delAvatarImg(String path){
        File file = new File(path);
        if (!file.delete()) {
            log.info("用户头像删除失败");
        }
    }

    @Async
    public void saveOperationLog(SysLog SysLog) {
        SysLogService.saveLog(SysLog);
    }
}
